package user.list;

public class Buffer<T> {

	private Element<T> first = null;
	private Element<T> last = null;

	public Buffer() {}

	public void push(T t) {
		Element<T> element = new Element<T>(t);
		if (this.first == null) {
			this.first = element;
			this.last = element;
		} else {
			this.last.setNext(element);
			this.last = element;
		}
	}

	public T pop() {
		if (this.first == null) return null;
		T toReturn = this.first.getCurrent();
		this.first = this.first.getNext();
		return toReturn;
	}

	public T peek() {
		if (this.first == null) return null;
		return this.first.getCurrent();
	}

//	public void push(T t) {
//		Element<T> element = new Element<T>(t);
//		synchronized (this.writesync) {
//			if (this.last != null) this.last.setNext(element);
//			else {
//				this.newFirst = element;
//				this.writesync.notifyAll();
//			}
//			this.last = element;
//		}
//	}
//
//	public T popHead() {
//		T toReturn;
//		synchronized (this.readsync) {
//			if (this.first == null) {
//				synchronized (this.writesync) {
//					if (this.newFirst == null) return null;
//					this.first = this.newFirst;
//					this.newFirst = null;
//				}
//			}
//			toReturn = this.first.getCurrent();
//			this.first = this.first.getNext();
//		}
//		return toReturn;
//	}
//
//	public T pop() {
//		synchronized (this.first) {
//			while (this.first == null) {
//				synchronized (writesync) {
//					
//				}
//			}
//		}
//	}
//
//	private boolean refreshFirst() {
//		synchronized (this.writesync) {
//			if (this.newFirst == null) return false;
//		}
//	}

}
